package hos.filex;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import java.io.File;
import java.util.List;

import hos.file.FileCollection;
import hos.file.FileResult;
import hos.file.FileStart;
import hos.file.media.FileType;
import hos.file.provider.FileProviderX;
import hos.file.provider.OnFileProviderListener;
import hos.filex.delegate.CameraDelegate;
import hos.filex.delegate.CameraImageDelegate;
import hos.filex.delegate.FileDelegate;
import hos.filex.delegate.OpenDelegate;
import hos.intent.IntentCollection;
import hos.intent.IntentResult;
import hos.intent.IntentStart;

/**
 * <p>Title: FileCompat </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-03-14 10:30
 */
public class FileX {
    //<editor-fold desc="FileProvider">

    public static void setFileProvider(OnFileProviderListener listener) {
        FileProviderX.setFileProvider(listener);
    }

    //</editor-fold>

    //<editor-fold desc="Authority">

    public static void setAuthority(Context context, String authority) {
        FileProviderX.setAuthority(context, authority);
    }
    //</editor-fold>

    //<editor-fold desc="Delegate">
    public static OpenDelegate open(@NonNull ComponentActivity activity) {
        return OpenDelegate.create(activity);
    }

    public static OpenDelegate open(@NonNull Fragment fragment) {
        return OpenDelegate.create(fragment);
    }

    public static FileDelegate file(@NonNull ComponentActivity activity) {
        return FileDelegate.create(activity);
    }

    public static FileDelegate file(@NonNull Fragment fragment) {
        return FileDelegate.create(fragment);
    }

    public static CameraImageDelegate cameraImage(@NonNull ComponentActivity activity) {
        return CameraImageDelegate.create(activity);
    }

    public static CameraImageDelegate cameraImage(@NonNull Fragment fragment) {
        return CameraImageDelegate.create(fragment);
    }

    public static CameraDelegate camera(@NonNull ComponentActivity activity) {
        return CameraDelegate.create(activity);
    }

    public static CameraDelegate camera(@NonNull Fragment fragment) {
        return CameraDelegate.create(fragment);
    }
    //</editor-fold>

    //<editor-fold desc="OpenFile">
    public static boolean openFile(Context context, String filePath, int requestCode) {
        return FileStart.openFile(context, filePath, requestCode);
    }

    public static boolean openFile(Context context, String pkgName, String filePath, int requestCode) {
        return FileStart.openFile(context, pkgName, filePath, requestCode);
    }

    public static boolean openWps(Context context, String filePath) {
        Intent wps = FileCollection.getWps(context, filePath);
        return IntentCollection.startResult(context, wps);
    }

    public static boolean openUrl(Context context, String filePath, int requestCode) {
        return IntentStart.openUrl(context, filePath, requestCode);
    }

    public static boolean openMarket(Context context, String filePath, int requestCode) {
        return IntentStart.openMarket(context, filePath, requestCode);
    }
    //</editor-fold>


    //<editor-fold desc="Camera">

    /**
     * 拍照
     */
    public static Uri createImage(Activity activity, int requestCode, String fileName) {
        return FileStart.createImage(activity, fileName, requestCode);
    }

    /**
     * 录音
     */
    public static Uri createAudio(Activity activity, int requestCode, String fileName) {
        return FileStart.createAudio(activity, fileName, requestCode);
    }

    /**
     * 摄像
     */
    public static Uri createVideo(Activity activity, int requestCode, String fileName) {
        return FileStart.createVideo(activity, fileName, requestCode);
    }

    /**
     * 拍照
     */
    public static Uri createImage(Activity activity, int requestCode) {
        return createImage(activity, requestCode, null);
    }

    /**
     * 录音
     */
    public static Uri createAudio(Activity activity, int requestCode) {
        return createAudio(activity, requestCode, null);
    }

    /**
     * 摄像
     */
    public static Uri createVideo(Activity activity, int requestCode) {
        return createVideo(activity, requestCode, null);
    }

    //</editor-fold>


    //<editor-fold desc="ResultFile">
    public static File getMedia(Context context, int resultCode,
                                Intent intent, Uri uri
    ) {
        return FileResult.getMedia(context, resultCode, intent, uri);
    }

    public static File getFile(Context context, int resultCode,
                               Intent intent
    ) {
        return FileResult.getFile(context, resultCode, intent);
    }

    public static List<File> getFileList(Context context, int resultCode,
                                         Intent intent
    ) {
        return FileResult.getFileList(context, resultCode, intent);
    }

    //</editor-fold>

    //<editor-fold desc="ResultUri">
    public static Uri getCameraUri(int resultCode, Intent intent, Uri uri) {
        return IntentResult.getMediaUri(resultCode, intent, uri);
    }

    public static Uri getUri(int resultCode, Intent intent) {
        return IntentResult.getFileUri(resultCode, intent);
    }

    public static List<Uri> getUriList(int resultCode, Intent intent) {
        return IntentResult.getFileListUri(resultCode, intent);
    }
    //</editor-fold>

    //<editor-fold desc="Content">

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseContent(Activity activity, int requestCode, FileType.Type type) {
        return FileStart.chooseContent(activity, requestCode, type);
    }

    /**
     * 选择文件
     */
    public static boolean chooseContentList(Activity activity, int requestCode, FileType.Type type) {
        return FileStart.chooseContentList(activity, requestCode, type);
    }
    //</editor-fold>

    //<editor-fold desc="Document">

    /**
     * 选择文件
     */
    public static boolean chooseDocument(Activity activity, int requestCode, FileType.Type... type) {
        return FileStart.chooseDocument(activity, requestCode, type);
    }

    /**
     * 选择文件
     */
    public static boolean chooseDocumentList(Activity activity, int requestCode, FileType.Type... type) {
        return FileStart.chooseDocumentList(activity, requestCode, type);
    }
    //</editor-fold>

    //<editor-fold desc="ImageVideo">
    public static boolean chooseImageVideo(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.IMAGE, FileType.Type.VIDEO);
    }

    /**
     * 选择文件
     */
    public static boolean chooseImageVideoDocumentList(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.IMAGE, FileType.Type.VIDEO);
    }
    //</editor-fold>

    //<editor-fold desc="Image">
    public static boolean chooseImage(Activity activity, int requestCode) {
        return chooseContent(activity, requestCode, FileType.Type.IMAGE);
    }

    /**
     * 选择文件
     */
    public static boolean chooseImageList(Activity activity, int requestCode) {
        return chooseContentList(activity, requestCode, FileType.Type.IMAGE);
    }

    public static boolean chooseImageDocument(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.IMAGE);
    }

    /**
     * 选择文件
     */
    public static boolean chooseImageDocumentList(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.IMAGE);
    }
    //</editor-fold>

    //<editor-fold desc="Video">
    public static boolean chooseVideo(Activity activity, int requestCode) {
        return chooseContent(activity, requestCode, FileType.Type.VIDEO);
    }

    /**
     * 选择文件
     */
    public static boolean chooseVideoList(Activity activity, int requestCode) {
        return chooseContentList(activity, requestCode, FileType.Type.VIDEO);
    }

    public static boolean chooseVideoDocument(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.VIDEO);
    }

    /**
     * 选择文件
     */
    public static boolean chooseVideoDocumentList(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.VIDEO);
    }
    //</editor-fold>
}
